<?php
/**
 * Created by Benjiemin
 * Date: 2020/3/4
 * Time: 20:26
 */
require ('./vendor/autoload.php');
use QL\QueryList;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;
/*
$baseUrl = 'http://www.xiaoyu.com/';
//启用cokies
$jar = new \GuzzleHttp\Cookie\CookieJar;
$client = new GuzzleHttp\Client(['cookies' => true]);

$onRedirect = function(
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
) {
    echo 'Redirecting! ' . $request->getUri() . ' to ' . $uri . "\n";
};

//登录
$ql = $client->request('POST',$baseUrl.'login',[
    'form_params'=>[
        'jumpurl' => 'http://www.xmfish.com/',
        'loginurl' => 'http://bbs.xmfish.com/login.php',
        'action'=>'bbs',
        'bbs_id'=>'',
        'username'=>'tulouguli',
        'password'=>'jian168@',
    ],
    'allow_redirects' => false
]);

sleep(1);

//跳转
$url = 'http://www.xmfish.com';
$ql = $client->request('GET',$url);
//跳转
$url = 'http://www.xmfish.com/detail.php?id=11133';
$ql = $client->request('GET',$url);
//获取文件头
echo json_encode($ql->getStatusCode());die;
//帖子内容：
$content = '我司放假都没给钱，复工开始算';
$tid = 16687590;
//进入论坛，获取全部板块
$ql = $client->request('POST','http://bbs.xmfish.com/post.php?fid=6',[
    'form_params'=>[
        'atc_usesign' => '1',
        'replytouser' => '',
        'atc_convert'=>'1',
        'atc_autourl'=>'1',
        'step'=>'2',
        'type'=>'',
        'action'=>'reply',
        'fid'=>'6',
        'cyid'=>'',
        'tid'=>$tid,
        'stylepath'=>'wind',
        'ajax'=>'',
        'verify'=>'c91dbad1',
        '_hexie'=>'e7a19065',
        'iscontinue'=>'0',
        'atc_title'=>'',
        'atc_content'=>$content,
        'usernames'=>'',
        'go_lastpage'=>'1',
    ]
]);

echo $ql->getBody();die;*/
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', 'http://bbs.xmfish.com');

echo $response->getStatusCode(); // 200
echo $response->getHeaderLine('content-type'); // 'application/json; charset=utf8'
echo $response->getBody(); // '{"id": 1420053, "name": "guzzle", ...}'

// Send an asynchronous request.
$request = new \GuzzleHttp\Psr7\Request('GET', 'http://bbs.xmfish.com/login.php');
$promise = $client->sendAsync($request)->then(function ($response) {
    echo 'I completed! ' . $response->getBody();
});

$promise->wait();

